﻿//============================================================
//write by bxl at 2021-06-03 21:51:47
//============================================================
using System.Collections.Generic;
using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.SpecificServiceType;
using BCDto.TMS.TransferStation;
using BCEntity.TMS.SpecificServiceType;
using BCService.TMS.SpecificServiceType;
using BCService.TMS.TransferStation;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;


namespace BCTMSRESTful.Controllers.Management.TMS.SpecificServiceType
{
    /// <summary>
    /// 特殊服务类型接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class SpecificServiceTypeController : ManagementBaseController
    {
        #region var
        private ISpecificServiceTypeService specificServiceTypeService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public SpecificServiceTypeController(ISpecificServiceTypeService specificServiceTypeService)
        {
            this.specificServiceTypeService = specificServiceTypeService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新特殊服务类型纪录
        /// </summary>
        /// <param name="dto">特殊服务类型数据模型</param>
        /// <returns></returns>
        [Log("添加新特殊服务类型纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(SpecificServiceTypeRequestDto), 200)]
        [ProducesResponseType(typeof(ErrorMessageDto), 400)]
        [ProducesResponseType(typeof(ErrorMessageDto), 401)]
        [ProducesResponseType(typeof(ErrorMessageDto), 500)]
        public IActionResult Post([FromBody] SpecificServiceTypeRequestDto dto)
        {
            var a = specificServiceTypeService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改特殊服务类型纪录
        /// </summary>
        /// <param name="dto">特殊服务类型数据模型</param>
        /// <returns></returns>
        [Log("修改特殊服务类型纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(SpecificServiceTypeViewDto), 200)]
        public IActionResult Put([FromBody] SpecificServiceTypePutDto dto)
        {
            var a = Ok(specificServiceTypeService.Update(dto, this.Admin));
            return a;
        }
        #endregion


        #region 启用/禁用特殊服务类型纪录重写
        /// <summary>
        /// 启用/禁用特殊服务类型纪录重写
        /// </summary>
        /// <param name="specificServiceTypeId">特殊服务类型纪录id</param>
        /// <param name="enabled">启用/禁用</param>
        /// <returns></returns>
        [Log("启用/禁用特殊服务类型纪录")]
        [HttpPut("[action]/{specific_service_type_id}/{enabled}")]
        [ProducesResponseType(typeof(SpecificServiceTypeViewDto), 200)]
        public IActionResult Enable(
            [FromRoute(Name = "specific_service_type_id")] int specificServiceTypeId,
            [FromRoute(Name = "enable")] bool enabled)
        {
            return Ok(specificServiceTypeService.UpdateEnable(this.Admin, specificServiceTypeId, enabled));
        }
        #endregion


        #region 删除  
        /// <summary>
        /// 删除特殊服务类型纪录
        /// </summary>
        /// <param name="specificServiceTypeId">特殊服务类型ID</param>
        /// <returns></returns>
        [Log("删除特殊服务类型纪录")]
        [HttpDelete("{specific_service_type_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "specific_service_type_id")] int specificServiceTypeId)
        {
            specificServiceTypeService.Delete(specificServiceTypeId, this.Admin);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条特殊服务类型纪录
        /// </summary>
        /// <param name="specificServiceTypeId">特殊服务类型ID</param>
        /// <returns></returns>
        [HttpGet("{specific_service_type_id}")]
        [ProducesResponseType(typeof(SpecificServiceTypeDto), 200)]
        public IActionResult Get([FromRoute(Name = "specific_service_type_id")] int specificServiceTypeId)
        {
            return (Ok(specificServiceTypeService.GetById(specificServiceTypeId)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询特殊服务类型
        /// </summary> 
        /// <param name="enabled">启用</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<SpecificServiceTypeDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "enabled")] bool? enabled,
            [FromQuery(Name = "index")] int? pageIndex = 1,
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(specificServiceTypeService.GetList(Admin,enabled, pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion


        #region GetOnlyList
        /// <summary>
        /// 获取特殊服务类型纪录
        /// </summary>
        /// <param name="enabled">启用</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(List<SpecificServiceTypeDto>), 200)]
        public IActionResult GetList([FromQuery(Name = "enabled")] bool? enabled)
        {
            return Ok(specificServiceTypeService.GetOnlyList(enabled));

        }
        #endregion
    }
}